from arquivo import lerArquivo
from cluster import KMeans
from numpy import random

class RadialBasisFunctions():

    def __init__(self,treinamento,teste,taxaAprendizagem,numClusters):
        self.treinamento = lerArquivo(treinamento)
        self.teste = lerArquivo(teste)
        self.taxaAprendizagem = taxaAprendizagem
        self.clusters = [None]*numClusters
        self.vetorPesosSaida = random.uniform(low=-1,high=1,size=(numClusters, 2))
        self.vetorSaidaRBF = [None]*numClusters
        self.vetorResposta = [None]*2
        self.varClusters = [None]*numClusters
        
    def computePropagacao(self):
        for cluster in self.clusters:
            for padrao in self.treinamento:
                cluster.append(padrao)
                
    def computeClusters(self):
        kmeans = KMeans(self.numClusters, self.treinamento)
        kmeans.executar()
        self.varClusters = kmeans.varClusters
        return kmeans.getCentroides()
    
    def computeFuncaoBaseRadial(self,centros,campoReceptivo):
        return "TODO"
    
    def computeOutput(self):
        for l in range(len(self.vetorResposta)):
            output = 0.0
            for i in range(len(self.clusters)):
                output += self.vetorPesosSaida[i][l]*self.vetorSaidaRBF[i]
            self.vetorResposta[l] = output
            
    def processar(self):
        parada = False
        while parada:
            self.computePropagacao()
            centroides = self.computeClusters()
            self.computeFuncaoBaseRadial(centroides, self.varClusters)
            self.computeOutput()
            parada = self.computeCriterioParada()
            
    def computeCriterioParada(self):
        return True
        